// pages/compony-pages/compony-recruit/compony-recruit.js
const app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        pageSize: 10,
        pageIndex: -1,
        hasMore: true,
        jobList:[]
    },
    /**
     * ===================事件处理部分===================
     */
    selectItem(e){
        let index = e.currentTarget.dataset.index;
        let parmas = {
            jobId: this.data.jobList[index].Id,
            jobName: this.data.jobList[index].JobName,
            flag:1
        }
        wx.navigateTo({
            url: '/pages/compony-pages/job-detail/job-detail?parmas='+JSON.stringify(parmas)
        });
    },
    /**
     * ===================事件处理部分===================
     */

    /**
     * -------------------网络请求部分-------------------
     */
    getEnterpriseJobList(){
        let that = this;
        if (!that.data.hasMore) return;
        wx.showLoading({
            title: '加载中...',
            mask: true
        });
        let pageI = ++that.data.pageIndex;
        let data = {
            pageSize: that.data.pageSize,
            pageIndex: pageI,
            currentUserInfoId: app.userInfo.Id,
            enterpriseInfoId: app.globalData.enterpriseInfo.Id
        };
        that.setData({
            pageIndex: pageI
        });
        wx.request({
            url: app.globalData.serverAddress.getEnterpriseJobs,
            data: data,
            header: {
                'Authorization': "Bearer " + app.globalData.token
            },
            method: 'GET',
            success: function(res) {
                console.log(res.data.BodyContent);
                if (res.statusCode == 200) {
                    if (res.data.CodeStatus == 20000) {
                        let count = res.data.BodyContent.TotalCount;
                        let flag = (that.data.pageIndex + 1) * that.data.pageSize < count;
                        // console.log(flag);
                        var newList = that.data.jobList.concat(res.data.BodyContent.List);
                        that.setData({
                            jobList: newList,
                            hasMore: flag
                        });
                    } 
                    else {
                        that.setData({
                            hasMore: false
                        });
                        let msg = res.data.Message;
                    }
                }
            },
            fail: function (res) { console.log("getEnterpriseJobList fail" , res)},
            complete: function(res) {wx.hideLoading()},
        })
    },
    /**
     * -------------------网络请求部分-------------------
     */

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        this.getEnterpriseJobList();
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
        
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {
        this.getEnterpriseJobList();
    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})